// ==++== 
//
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
// ==--== 
/*============================================================
** 
** Class: SafePipeHandle 
**
============================================================*/ 
namespace Microsoft.Win32.SafeHandles {

using System;
using System.Runtime.Versioning;
using System.Security.Permissions;

    // <SecurityKernel Critical="True" Ring="0"> 
    // <SatisfiesLinkDemand Name="SafeHandleZeroOrMinusOneIsInvalid" />
    // </SecurityKernel>
#pragma warning disable 618    // Have not migrated to v4 transparency yet
    [System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)] 
#pragma warning restore 618
    [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)] 
    [HostProtection(MayLeakOnAbort = true)] 
    public sealed class SafePipeHandle : SafeHandleZeroOrMinusOneIsInvalid {
// ReSharper disable UnusedMember.Local
        private SafePipeHandle() 
// ReSharper restore UnusedMember.Local
            : base(true) { }

        public SafePipeHandle(IntPtr preexistingHandle, bool ownsHandle)
            : base(ownsHandle) { 
            SetHandle(preexistingHandle);
        } 
 
        [ResourceExposure(ResourceScope.Machine)]
        [ResourceConsumption(ResourceScope.Machine)] 
        protected override bool ReleaseHandle() {
            return UnsafeNativeMethods.CloseHandle(handle);
        }
    } 

} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
